﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using YKXiangQi.Common;
using YKXiangQi.ViewModels;


namespace YKXiangQi.Controls
{
    public partial class DockableControl : UserControl
    {
        public DockableControl()
        {
            InitializeComponent();
        }

        public static readonly DependencyProperty CloseCommandProperty =
            DependencyProperty.Register("CloseCommand", typeof (ICommand), typeof (DockableControl),
                                        new PropertyMetadata(default(ICommand)));

        //public static readonly DependencyProperty CloseCommandParameterProperty =
        //    DependencyProperty.Register("CloseCommandParameter", typeof (object), typeof (DockableControl),
        //                                new PropertyMetadata(default(object)));

        public static readonly DependencyProperty ItemsSourceProperty =
            DependencyProperty.Register("ItemsSource", typeof (IEnumerable<DockableViewModel>), typeof (DockableControl),
                                        new PropertyMetadata(default(IEnumerable<DockableViewModel>)));

        public IEnumerable<DockableViewModel> ItemsSource
        {
            get { return (IEnumerable<DockableViewModel>)GetValue(ItemsSourceProperty); }
            set { SetValue(ItemsSourceProperty, value); }
        }


        public static readonly DependencyProperty SelectedItemProperty =
            DependencyProperty.Register("SelectedItem", typeof (DockableViewModel), typeof (DockableControl),
                                        new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));

        public DockableViewModel SelectedItem
        {
            get { return (DockableViewModel) GetValue(SelectedItemProperty); }
            set { SetValue(SelectedItemProperty, value); }
        }

        //public object CloseCommandParameter
        //{
        //    get
        //    {
        //        return GetValue(CloseCommandParameterProperty);
        //    }
        //    set
        //    {
        //        SetValue(CloseCommandParameterProperty, value);
        //    }
        //}

        public ICommand CloseCommand
        {
            get
            {
                return (ICommand) GetValue(CloseCommandProperty);
            }
            set
            {
                SetValue(CloseCommandProperty, value);
            }
        }

        private void OnClose(object sender, MouseButtonEventArgs e)
        {
            if (CloseCommand != null)
                CloseCommand.Execute(null);
        }

    }

}
